/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

/**
 * Il s'agit des donnees (parametres).
 * Une fois chargees, les donnees ne varient pas au fil du programme, elles sont constantes et non modifiables.
 * Implemente ComboBoxModel pour la liste deroulante de la GUI.
 * @author Jo
 */
public class Modele implements ComboBoxModel{

    
    
    private String chemin_fichier = "src/modele/parametres.csv";
    public List<SetParams> sets;
    
    public Modele(){
        sets = new ArrayList<SetParams>();
        chargerFromFichier();
    }
    
    private void chargerFromFichier(){
        
        try {
            BufferedReader out = new BufferedReader(new FileReader(chemin_fichier));
            
            String line;
            String[] lineSplited;
            while( ( line = out.readLine() ) !=null ) {
                
                lineSplited = line.split(";");
                if(lineSplited.length >= 7){
                    SetParams set = new SetParams(
                            Double.valueOf(lineSplited[0]), 
                            Double.valueOf(lineSplited[1]), 
                            Double.valueOf(lineSplited[2]), 
                            Double.valueOf(lineSplited[3]), 
                            Double.valueOf(lineSplited[4]), 
                            Double.valueOf(lineSplited[5]), 
                            Integer.valueOf(lineSplited[6])
                            );
                    sets.add(set);
                }
            }
            
        } catch (IOException ex) {
            Logger.getLogger(Modele.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    //
    SetParams selection = null;
    
    @Override
    public void setSelectedItem(Object anItem) {
        selection = (SetParams) anItem;
    }

    @Override
    public Object getSelectedItem() {
        return selection;
    }

    @Override
    public int getSize() {
        return sets.size();
    }

    @Override
    public Object getElementAt(int index) {
        return sets.get(index);
    }

    @Override
    public void addListDataListener(ListDataListener l) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeListDataListener(ListDataListener l) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
